package cn.itcast.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 需求：可以发送get请求和post请求得到1到100之间的和
 */
public class ServletSum extends HttpServlet {
	private static final long serialVersionUID = 1L;


	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		int sum = 0;
		for (int i = 1; i <= 100; i++) {
		    sum += i;
		}
	    // 两种打印方法
		// 1、向控制台console打印
		System.out.println(sum);
		// 2、向浏览器输出
		PrintWriter out = response.getWriter();
		out.println(sum);
	}
	
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
